//
//  PersonalCell.swift
//  HealthMonitoring
//
//  Created by YTYanK on 2018/7/19.
//  Copyright © 2018年 YTYanK. All rights reserved.
//

import UIKit
import SwiftyJSON

class PersonalCell: HMTableViewCell {
    let icon = UIImageView()
    let nickName = UILabel()
    let describe = UILabel()
    let describe2 = UILabel()
    let img = UIImageView()
    // 用户的id
    var id = ""
    override func setupViews(view: UIView) {
        view.addSubview(icon)
        view.addSubview(nickName)
        view.addSubview(describe)
        view.addSubview(img)
        
        icon.centerYAlign(view: view)
        icon.leadingAlign(view: view, predicate: "20")
        icon.heightConstrain(predicate: "66")
        icon.widthConstrain(predicate: "66")
        icon.layer.cornerRadius = (66/2)
        icon.layer.masksToBounds = true
        
        nickName.centerYAlign(view: view, predicate: "-15")
        nickName.leadingHorizontally(view: icon, predicate: "20")

        
        describe.centerYAlign(view: view, predicate: "15")
        describe.leadingHorizontally(view: icon, predicate: "20")

        
        img.centerYAlign(view: view)
        img.trailingAlign(view: view, predicate: "-20")
        img.widthConstrain(predicate: "20")
        img.heightConstrain(predicate: "20")
        img.imgName(name: "ringht.png")
        
        updatePersonalData()
    }
    
    func updatePersonalData() {
        let dic =  HMLoginParam.share.user
        let _imgUrl = configure.shareConfigure.IP_diagonal + (dic["iconUrl"] as! String)
        icon.img(url: _imgUrl)
        
        nickName.text = (dic["nickname"] as! String)
        
        let _sex = (dic["sex"] as! Int) == 1 ? "男" : "女"
        let h =  dic["height"] as! Int
        let w = dic["weight"] as! Int
        describe.text = _sex + " \(h)"  + "cm " +  "\(w)kg"
    }
    
    
    override func setJson(json: JSON) {
        self.id = json["id"].stringValue
        self.describe.text = json["phone"].stringValue
        self.nickName.text = json["nickname"].stringValue
        let _imgUrl = configure.shareConfigure.IP_diagonal + (json["iconUrl"].stringValue)
        self.icon.img(url: _imgUrl)
    }
    
    
}
